<template>
	<view>
		<uni-card title="曾欣祺" sub-title="健康生活,规律学习" extra="" :thumbnail="avatar">
			<text class="uni-body">每日打卡，养成好习惯</text>
		</uni-card>
		<view style="text-align:center;margin: 20%;">
			<uni-icons  type="location" size="200"></uni-icons>
			<!-- <button class="button popup-success" @click="messageToggle('success')">
				<text class="button-text success-text">点击打卡</text>
			</button> -->
			<uni-data-select
			        v-model="formdate.clocktype"
			        :localdata="types">
			</uni-data-select>
			<uni-easyinput style="margin-top: 10%;" type="textarea" v-model="formdate.clockinfo" placeholder="有什么想说的话"></uni-easyinput>
		
			<button style="margin: 10%;" @tap="modalTap" type="primary" plain="true" @click="messageToggle('success')">{{msg_text}}</button>
			<button @tap="historyclock">查看历史打卡</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return { 
				dis:true,
				types:[
				  { value: "早起", text: "早起" },
				  { value: "小测", text: "小测" },
				  { value: "英语", text: "英语" },
				  { value: "阅读", text: "阅读" },
				],
				msg_text:"点击打卡",
				baseurl: "http://localhost:8000/",
				avatar: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png',
				formdate:{
					clockid:0,
					clocktime:0,
					clocktype:"",
					clockinfo:"",
				}
			}
		},
		onLoad() {

		},
		methods: {
			historyclock(){
				uni.navigateTo({
					url:"/pages/clockhistory/clockhistory",
				});
			},
			modalTap: function(e) {
				this.formdate.clocktime=Date.now();
				console.log(this.formdate);
				uni.request({
					url:this.baseurl+"clock/addclock",
					method:"POST",
					data:this.formdate,
					success: (res) => {
						if (res.data.code=="0000"){
							uni.showModal({
								title: '打卡成功',
								content: '恭喜你，打卡成功',
								showCancel: false,
								confirmText: '确定'
							});
							this.formdate={
								clockid:0,
								clocktime:0,
								clocktype:"",
								clockinfo:"",
							};
						}
						else{
							uni.showModal({
								title: '打卡失败',
								content: '未知错误，请联系管理员',
								showCancel: false,
								confirmText: '确定'
							});
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>
